/**删除***/
$("#info_delete").click(function () {
    var act = $(this).attr('id');
    var value = new Array();
    $("tbody span[class='checked'] input").each(function (a, b) {
        value[a] = 'id=' + $(this).val();
    });
    var ids = value.join('&');
    var confirm_msg = "确认删除Banner图吗?";
    if(ids==''){
        dshow('请选择至少一条数据进行操作');
        return false;
    }
    if (confirm(confirm_msg)) {
        $.ajax({
            url: '/banner/delBanner',
            type: 'POST',
            data: {ids: ids, act: act},
            dataType: 'JSON',
            cache: false,
            success: function (json) {
                dshow(json.message);
                if (json.code == 2000) {
                    window.location.href = '/banner';
                }
            }
        });
    }
});

$(".update").click(function () {
    var id = $(this).attr('data-id');
    var page = $("input[name='page']").val();
    window.location.href = '/banner/update?page=' + page + '&id=' + id;
});

/**
 * 改变排序
 * @param sort
 * @param wine_id
 */
function changeSort(sort,wine_id) {
    var data = $("#searchform").serialize();
    var sort_val=  $("input[data-wine="+wine_id+"]").val();
    $.ajax({
        url: '/banner/sortBanner',
        type: 'POST',
        data: {sort: sort_val, wine_id: wine_id},
        dataType: 'JSON',
        cache: false,
        success: function (json) {
            if (json.code == 2000) {
                dshow(json.message);
                window.location.href = '/banner' + data;
            }else{
                dshow(json.message);
            }
        }
    });
}

$(".reset,.start").click(function () {
    var act = $(this).attr('data-id');
    var class_name = $(this).attr('data-class');
    if(class_name=='reset'){
        var confirm_msg = "确认禁用Banner图吗?";
        var status = 2;
    }else{
        var confirm_msg = "确认启用Banner图吗?";
        var status = 1;
    }

    if (confirm(confirm_msg)) {
        $.ajax({
            url: '/banner/statusBanner',
            type: 'POST',
            data: {status: status, act: act},
            dataType: 'JSON',
            cache: false,
            success: function (json) {
                dshow(json.message);
                if (json.code == 2000) {
                    window.location.href = '/banner';
                }
            }
        });
    }
});
